import axios from 'axios'; //导入axios对象
// import store from "../store";
//创建axios的对象
const Server = axios.create({
  //baseURL: import.meta.env.VITE_APP_BaseUrl as string, //请求接口的基地址
  //baseURL: 'https://20.200.163.145:9996/itsm',
  //baseURL: 'https://20.200.163.145:9998/itsm',
  baseURL:'https://20.200.163.145:9998/itsm',
  //baseURL:'http://192.168.99.123:9999',
  // baseURL: 'http://192.168.99.176:9999',
  // baseURL: 'http://20.198.118.93:9998/itsm',
  //baseURL: 'https://20.201.37.173:9999/itsm',
  //baseURL: 'https://www.ywglpt.psbc:8080/itsm',//正式环境
  timeout: 100000 //超时时间
});

//设置请求拦截器
Server.interceptors.request.use(
  (config:any) => {
    // store.state.isLoading = true
    //return config;
    const gloabalToken=localStorage.getItem('restructureGlobalToken')||'';
    console.log(config)
    if(config.url=='/openapi/common/getToken'){
      //config.headers._authToken = 'api09b1f57123678fe69c98c93666888';
      config.headers._authToken = 'api09b1f57123678fe69c98c93518624';
      //token（测试：api09b1f57123678fe69c98c93666888，生产：api09b1f57123678fe69c98c93518624）
    }else{
      config.headers._authToken =gloabalToken;
    }
    console.log("请求接口token",gloabalToken)
    
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
//设置响应拦截器
Server.interceptors.response.use(
  (response) => {
    if (response.status === 200) {
      // store.state.isLoading = false

      return Promise.resolve(response);
    } else {
      // store.state.isLoading = true

      return Promise.reject(response);
    }
    // return response;
  },
  (error) => {
    //   if (error.message.includes('timeout')) {
    //     // 判断请求异常信息中是否含有超时timeout字符串
    //     console.log('请求超时，请稍后再试');
    //     return Promise.reject(error);
    //     // reject这个错误信息
    //   }
    //   console.log('网络连接失败，请稍后再试');
    //   return Promise.reject(error);
    // }
    if (error.response.status) {
      return Promise.reject(error.response);
    }
    return Promise.reject(error);
  }
);

//导出Serve模块对象
export default Server;
